﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DataAccessLayer;
using GlobalObjects;
using System.Collections.Generic;

namespace DataAccessLayerTests
{
    [TestClass]
    public class SensorAccessTimeEntityTests
    {
        [TestMethod]
        public void insertOrUpdateAcceessTime_DAL_valid()
        {
            //arrange
            int sensorId = 2357;
            string dt = DateTime.UtcNow.ToString();
            SensorAccessTimeEntity sat = new SensorAccessTimeEntity();
            //act
            sat.insertOrUpdateAcceessTime_DAL(sensorId,dt);
            //assert
        }
        [TestMethod]
        public void insertOrUpdateAcceessTime_DAL_sameSensorId()
        {
            //arrange
            int sensorId = 1273;
            string dt = DateTime.Parse("11/07/2014 20:07:00").ToString();
            SensorAccessTimeEntity sat = new SensorAccessTimeEntity();
            //act
            sat.insertOrUpdateAcceessTime_DAL(sensorId, dt);
            //assert
        }
        [TestMethod]
        [ExpectedException(typeof(System.Data.Entity.Infrastructure.DbUpdateException))]
        public void insertOrUpdateAcceessTime_DAL_invalidSensorId()
        {
            //arrange
            int sensorId = 10273;
            string dt = DateTime.Parse("11/07/2012 20:07:00").ToString();
            SensorAccessTimeEntity sat = new SensorAccessTimeEntity();
            //act
            sat.insertOrUpdateAcceessTime_DAL(sensorId, dt);
            //assert
        }

        [TestMethod]
        public void setIp_DAL_valid() { 
            //arrange
            int sensorId = 1273;
            string ip = "1.1.1.1";
            SensorAccessTimeEntity sat = new SensorAccessTimeEntity();
            //act
            sat.setIp_DAL(sensorId,ip);
            //assert
        }

        [TestMethod]
        public void setFaultTolerance_DAL_valid()
        {
            //arrange
            int sensorId = 1273;
            int fault = 420;
            SensorAccessTimeEntity sat = new SensorAccessTimeEntity();
            //act
            sat.setFaultTolerance_DAL(sensorId, fault);
            //assert
        }
        [TestMethod]
        public void getAllSensors_DAL_valid() { 
            //arrange
            SensorAccessTimeEntity sat = new SensorAccessTimeEntity();
            //act
            List<SensorAccessTime> result =  sat.getAllSensors_DAL();
            //assert
            Assert.AreEqual(result[0].sensorId,1273);
            Assert.AreEqual(result[0].lastAccess, "11-Jul-14 8:07:00 PM");
            Assert.AreEqual(result[0].ip, "1.1.1.1");
            Assert.AreEqual(result[0].faultTolerance, 420);
            Assert.AreEqual(result.Count, 2); 
        }
    }
}
